<template>
  <div>
    <Breadcrumb>
      <BreadcrumbItem>理财产品增加</BreadcrumbItem>
    </Breadcrumb>
    <Divider />
    <i-form v-ref:form-validate :model="formDate" :rules="ruleValidate" :label-width="130">
        <Form-item label="理财产品名称" prop="productName">
            <i-input v-model="formDate.productName" placeholder="请输入理财产品名称" style="width:300px"></i-input>
        </Form-item>
         <Form-item label="理财产品种类" prop="categoryId">
            <i-input v-model="formDate.categoryId" placeholder="请输入理财产品种类" style="width:300px"></i-input>
        </Form-item>
         <Form-item label="理财产品利率" prop="productRate">
            <i-input v-model="formDate.productRate" placeholder="请输入理财产品利率" style="width:300px"></i-input>
        </Form-item>
         <Form-item label="理财产品存取类型" prop="accessType">
            <i-input v-model="formDate.accessType" placeholder="请输入理财产品存取类型" style="width:300px"></i-input>
        </Form-item>
        <Form-item label="理财产品期限" prop="accessPriod">
            <i-input v-model="formDate.accessPriod" placeholder="请输入理财产品期限" style="width:300px"></i-input>
        </Form-item>
        <Form-item label="最低买入金额" prop="minimumPerchase">
            <i-input v-model="formDate.minimumPerchase" placeholder="请输入最低买入金额" style="width:300px"></i-input>
        </Form-item>          
        <Form-item>
            <i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
            <i-button type="content" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
        </Form-item>
    </i-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formDate: {
        productId: "",
        productName: "",
        productRate: "",
        accessType: '',
        accessPriod: '',
        minimumPerchase: "",
        categoryId:"",
        categoryName: ""
      },
      ruleValidate: {
        productName: [
          { required: true, message: '理财产品名称不能为空', trigger: 'blur' }
        ],
        categoryName: [
          { required: true, message: '理财产品种类不能为空', trigger: 'blur' }
        ],
        productRate: [
          { required: true, message: '理财产品利率不能为空', trigger: 'blur' }
        ],
        accessType: [
          { required: true, message: '理财产品存取类型不能为空', trigger: 'blur' }
        ],
        accessPriod: [
          { required: true, message: '理财产品期限不能为空', trigger: 'blur' }
        ],
        minimumPerchase: [
          { required: true, message: '最低买入金额不能为空', trigger: 'blur' }
        ],
      }
    }
  },
  methods:{
    //提交
    handleSubmit:function (name) {
      this.$axios.post('product',{
        productId:this.formDate.productId,
        productName:this.formDate.productName,
        productRate:this.formDate.productRate,
        accessType:this.formDate.accessType,
        accessPriod:this.formDate.accessPriod,
        minimumPerchase:this.formDate.minimumPerchase,
        categoryId:this.formDate.categoryId,
        categoryName:this.formDate.categoryName,
      })
      .then(response=>{
        if(response.data.code==0){
          this.$router.push("propertygoods"),
          alert("添加成功")
        }
      }
      )
        .catch()
    },
//重置
    handleReset (name) {
      this.$refs[name].resetFields()
    }
  }
}
</script>

